<?php
header('Content-type: text/html');
//header('Content-Length: ' . filesize('download.php.src'));
header('Content-Disposition: attachment; filename="templates.html"');

echo '<h1>Template Backup</h1>'."\n\n";
$dirlist = opendir('./storage/templates/');
$files = array();
while( ($file = readdir($dirlist)) !== false) {
    if (strpos($file,'.tpl')) {
        echo '<h2>'.htmlspecialchars($file).'</h2>';
        $content = file('./storage/templates/'.$file);
        if (substr($file,0,4)!='inc_') {
            array_pop($content);
            array_shift($content);
        }
        $content = implode($content);
        echo '<textarea style="width:100%; height:200px;">'.htmlspecialchars($content).'</textarea>'."\n\n";
    }
}

?>